/*
 * Copyright 2025-2026 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package glz.hawk.poc.springboot.freemarker;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * This class is responsible for
 *
 * @author Zhang Peng
 */
@Controller
@RequestMapping("/users")
public class UserController {

    @GetMapping("/list")
    public String listUsers(Model model) {
        // 模拟数据
        List<User> users = Arrays.asList(
            new User(1, "Alice"),
            new User(2, "Bob")
        );

        // 向模板传递数据
        model.addAttribute("userList", users);
        model.addAttribute("currentTime", LocalDateTime.now());

        // 返回模板路径（自动定位到 templates/user/list.ftl）
        return "user/list";
    }
}
